home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 037a / tpfast40.zip / TPFKBD.ASM < prev    next >
Assembly Source File  |  1991-11-14  |  22KB  |  480 lines

  1. ;   _______________________________________________________________
  2. ;  |                                                               |
  3. ;  |            CopyRight (c) 1989,1990  Steven Lutrov             |
  4. ;  |_______________________________________________________________|____
  5. ;  |                                                               |    |
  6. ;  |  program title : fastkbd.asm                                  |    | ___
  7. ;  |  author        : Steven Lutrov                                |    |    |
  8. ;  |  revision      : 4.00                                         |    |    |
  9. ;  |  date          : 1991-11-01                                   |    |    |
  10. ;  |  language      : turbo assembler                              |    |    |
  11. ;  |                                                               |    |    |
  12. ;  |                                                               |    |    |
  13. ;  |  description   : assembly functions  for keyboard operations. |    |    |
  14. ;  |                : using int 16h or dos 21h.                    |    |    |
  15. ;  |                : tested on turbo pascal 5.0 & 5.5             |    |    |
  16. ;  |_______________________________________________________________|    |    |
  17. ;      |                                                                |    |
  18. ;      |________________________________________________________________|    |
  19. ;          |                                                                 |
  20. ;          |_________________________________________________________________|
  21. ;
  22.  
  23.  
  24. code segment word public
  25.  
  26. assume cs:code, ds:data
  27.  
  28. public  altkeydown,capslockdown,capslockon,freshchar,clearbuffer
  29. public  clearcapslock,clearins,clearnumlock,clearscrolllock,ctrlkeydown
  30. public  ekeypressed,getekey,getkey
  31. public  inskeydown,inskeyon,keypause
  32. public  leftshiftdown,nextkey,lastkey,numlockdown,numlockon
  33. public  rightshiftdown,scrolllockdown,scrolllockon,setcapslock
  34. public  setins,setnumlock,setscrolllock
  35.  
  36. data    segment
  37.         extrn  TPFError  :byte;
  38. data    ends
  39.  
  40.  
  41. ;-------------------------------------------------------------------------------
  42. ;function altkeydown: boolean;
  43. ;-------------------------------------------------------------------------------
  44. ;
  45. altkeydown proc far
  46.                 mov  ah,2                       ;bios kybd status func
  47.                 int  16h                        ;call the interrupt
  48.                 mov  bl,1                       ;true value
  49.                 test al,8                       ;test bit 3
  50.                 jnz  altkeydownl1               ;jump if true
  51.                 mov  bl,0                       ;false value
  52. altkeydownl1:   mov  al,bl                      ;place value for return
  53.                 ret
  54. altkeydown endp
  55.  
  56.  
  57.  
  58. ;-------------------------------------------------------------------------------
  59. ;function capslockdown: boolean;
  60. ;-------------------------------------------------------------------------------
  61. ;
  62. capslockdown proc far
  63.                 sub  ax,ax                      ;clear ax
  64.                 mov  es,ax                      ;point es to 0000:0000
  65.                 mov  si,418h                    ;offset of status byte
  66.                 mov  bl,64                      ;test bit 6
  67.                 mov  al,1                       ;true value
  68.                 test es:[si],bl                 ;test the bit
  69.                 jnz  capslockdownl1             ;jump if true
  70.                 mov  al,0                       ;false value
  71. capslockdownl1: ret
  72. capslockdown endp
  73.  
  74.  
  75. ;-------------------------------------------------------------------------------
  76. ;function capslockon: boolean;
  77. ;-------------------------------------------------------------------------------
  78. ;
  79. capslockon proc far
  80.                 mov  ah,2                       ;bios kybd status func
  81.                 int  16h                        ;call the interrupt
  82.                 mov  bl,1                       ;true value
  83.                 test al,64                      ;test bit 6
  84.                 jnz  capslockonl1               ;jump if true
  85.                 mov  bl,0                       ;false value
  86. capslockonl1:   mov  al,bl                      ;place value for return
  87.                 ret
  88. capslockon endp
  89.  
  90.  
  91. ;-------------------------------------------------------------------------------
  92. ;function freshchar :char;
  93. ;-------------------------------------------------------------------------------
  94. ;
  95. freshchar proc far
  96.                 mov  ah,0ch                     ;dos function number
  97.                 mov  al,7                       ;keyboard read function
  98.                 int  21h                        ;wait for a keystroke
  99.                 ret
  100. freshchar endp
  101.  
  102.  
  103. ;-------------------------------------------------------------------------------
  104. ;procedure clearbuffer;
  105. ;-------------------------------------------------------------------------------
  106. ;
  107. clearbuffer proc far
  108. clrbufferl1:    mov  ah,6                       ;function number
  109.                 mov  dl,0ffh                    ;subfunction number
  110.                 int  21h                        ;seek keystroke
  111.                 jnz  clrbufferl1                ;repeat if one found
  112.                 ret
  113. clearbuffer endp
  114.  
  115.  
  116. ;-------------------------------------------------------------------------------
  117. ;procedure clearcapslock;
  118. ;-------------------------------------------------------------------------------
  119. ;
  120. clearcapslock proc far
  121.                 sub  ax,ax                      ;clear ax
  122.                 mov  es,ax                      ;es pts to 0000:0000
  123.                 mov  al,10111111b               ;bit 6
  124.                 and  es:[417h],al               ;clear the bit
  125.                 ret
  126. clearcapslock endp
  127.  
  128.  
  129. ;-------------------------------------------------------------------------------
  130. ;procedure clearins;
  131. ;-------------------------------------------------------------------------------
  132. ;
  133. clearins  proc far
  134.                 sub  ax,ax                      ;clear ax
  135.                 mov  es,ax                      ;es pts to 0000:0000
  136.                 mov  al,01111111b               ;bit 7
  137.                 and  es:[417h],al               ;clear the bit
  138.                 ret
  139. clearins  endp
  140.  
  141.  
  142. ;-------------------------------------------------------------------------------
  143. ;procedure clearnumlock;
  144. ;-------------------------------------------------------------------------------
  145. ;
  146. clearnumlock proc far
  147.                 sub  ax,ax                      ;clear ax
  148.                 mov  es,ax                      ;es pts to 0000:0000
  149.                 mov  al,11011111B               ;bit 5
  150.                 and  es:[417H],al               ;clear the bit
  151.                 ret
  152. clearnumlock endp
  153.  
  154.  
  155. ;-------------------------------------------------------------------------------
  156. ;procedure clearscrolllock;
  157. ;-------------------------------------------------------------------------------
  158. ;
  159. clearscrolllock proc far
  160.                 sub  ax,ax                      ;clear ax
  161.                 mov  es,ax                      ;es pts to 0000:0000
  162.                 mov  al,11101111B               ;bit 4
  163.                 and  es:[417h],al               ;clear the bit
  164.                 ret
  165. clearscrolllock endp
  166.  
  167.  
  168. ;-------------------------------------------------------------------------------
  169. ;function ctrlkeydown: boolean;
  170. ;-------------------------------------------------------------------------------
  171. ;
  172. ctrlkeydown proc far
  173.                 mov  ah,2                       ;bios kybd status func
  174.                 int  16h                        ;call the interrupt
  175.                 mov  bl,1                       ;true value
  176.                 test al,4                       ;test bit 2
  177.                 jnz  ctrlkeydownl1              ;jump if true
  178.                 mov  bl,0                       ;false value
  179. ctrlkeydownl1:  mov  al,bl                      ;place value for return
  180.                 ret
  181. ctrlkeydown endp
  182.  
  183.  
  184.  
  185. ;-----------------------------------------------------------------------------
  186. ; function ekeypressed    :boolean;
  187. ;-----------------------------------------------------------------------------
  188. ekeypressed   proc far
  189.                 mov     Ah,011H                 ;extended keyboard service
  190.                 int     16H                     ;go to bios
  191.                 jz      ekey1                   ;jump if no key ready
  192.                 mov     Al,1                    ;set Al to equal true (1)
  193.                 ret                             ;return from sub
  194. ekey1:          xor     Al,Al                   ;set Al to false (0)
  195.                 ret                             ;return from sub
  196. endp    ekeypressed
  197.  
  198.  
  199. ;-----------------------------------------------------------------------------
  200. ; function getekey   :word;
  201. ;-----------------------------------------------------------------------------
  202. getekey  proc  far
  203.                 mov     Ah,010H                 ;extended keyboard char read
  204.                 int     16H                     ;go to bios
  205.                 ret                             ;return from sub
  206. endp    getekey
  207.  
  208.  
  209. ;-----------------------------------------------------------------------------
  210. ;function getkey  :word;
  211. ;-----------------------------------------------------------------------------
  212. getkey  proc far
  213.                 mov     ah,00H                  ;get next keyboard char
  214.                 int     16H                     ;go to bios
  215.                 ret                             ;return from sub
  216. endp    getkey
  217.  
  218.  
  219. ;-------------------------------------------------------------------------------
  220. ;function inskeydown: boolean;
  221. ;-------------------------------------------------------------------------------
  222. ;
  223. inskeydown proc far
  224.                 sub  ax,ax                      ;clear ax
  225.                 mov  es,ax                      ;point es to 0000:0000
  226.                 mov  si,418h                    ;offset of status byte
  227.                 mov  bl,128                     ;test bit 7
  228.                 mov  al,1                       ;true value
  229.                 test es:[si],bl                 ;test the bit
  230.                 jnz  inskeydownl1               ;jump if true
  231.                 mov  al,0                       ;false value
  232. inskeydownl1:   ret
  233. inskeydown endp
  234.  
  235.  
  236. ;-------------------------------------------------------------------------------
  237. ;function inskeyon: boolean;
  238. ;-------------------------------------------------------------------------------
  239. ;
  240. inskeyon proc far
  241.                 mov  ah,2                       ;bios kybd status func
  242.                 int  16h                        ;call the interrupt
  243.                 mov  bl,1                       ;true value
  244.                 test al,128                     ;test bit 7
  245.                 jnz  inskeyonl1                 ;jump if true
  246.                 mov  bl,0                       ;false value
  247. inskeyonl1:     mov  al,bl                      ;place value for return
  248.                 ret
  249. inskeyon endp
  250.  
  251.  
  252. ;-------------------------------------------------------------------------------
  253. ;procedure keypause(code :char; ascii: boolean; wait_a,wait_b :byte;);
  254. ;-------------------------------------------------------------------------------
  255. ;
  256. keypause proc far
  257.                 sti                             ;enable interrupts
  258.                 push bp                         ;save bp
  259.                 mov  bp,sp                      ;set up stack frame
  260.                 mov  bh,[bp+12]                 ;code to bh
  261.                 mov  bl,[bp+10]                 ;extended code flag to bl
  262.                 sub  ax,ax                      ;get wait_a
  263.                 mov  al,[bp+8]                  ;
  264.                 mov  si,ax                      ;first char delay
  265. keypausel1:     mov  ah,0                       ;function to read timer
  266.                 int  1ah                        ;time to cx:dx
  267.                 add  dx,si                      ;add delay to low word
  268.                 mov  di,dx                      ;copy to di
  269. keypausel2:     int  1ah                        ;keep reading time...
  270.                 cmp  dx,di                      ;delay complete?
  271.                 jne  keypausel2                 ;jump if not
  272.                 mov  ah,1                       ;bios func to chk buffer
  273.                 int  16h                        ;check for character
  274.                 jz   keypausel5                 ;quit if buffer empty
  275.                 cmp  al,bl                      ;see if extended code
  276.                 jne  keypausel3                 ;jump if not extended
  277.                 mov  al,ah                      ;else shift code to al
  278. keypausel3:     cmp  al,bh                      ;is it the right code?
  279.                 jne  keypausel5                 ;quit routine if not
  280. keypausel4:     mov  ah,6                       ;now clear buffer
  281.                 mov  dl,0ffh                    ;dos func to read char
  282.                 int  21h                        ;read char w.o. waiting
  283.                 jnz  keypausel4                 ;read again if char found
  284.                 sub  ax,ax                      ;fetch wait_b
  285.                 mov  al,[bp+6]                  ;
  286.                 mov  si,ax                      ;typematic delay
  287.                 jmp  short keypausel1           ;go check buffer again
  288. keypausel5:     pop  bp                         ;restore bp and quit
  289.                 ret  4
  290. keypause endp
  291.  
  292.  
  293. ;-------------------------------------------------------------------------------
  294. ;function leftshiftdown: boolean;
  295. ;-------------------------------------------------------------------------------
  296. ;
  297. leftshiftdown proc far
  298.                 mov  ah,2                       ;bios kybd status func
  299.                 int  16h                        ;call the interrupt
  300.                 mov  bl,1                       ;true value
  301.                 test al,2                       ;test bit 1
  302.                 jnz  lsdownl1                   ;jump if true
  303.                 mov  bl,0                       ;false value
  304. lsdownl1:       mov  al,bl                      ;place value for return
  305.                 ret
  306. leftshiftdown endp
  307.  
  308.  
  309.  
  310. ;-------------------------------------------------------------------------------
  311. ;function nextkey :char;
  312. ;-------------------------------------------------------------------------------
  313. ;
  314. nextkey proc far
  315.                 mov  TPFError,2                ;2 = no keystroke in buffer
  316.                 mov  al,0ffh                    ;assume no keystroke
  317.                 mov  ah,1                       ;bios func to chk buffer
  318.                 int  16h                        ;chk for keystroke
  319.                 jz   nextkeyl1                  ;jump if buffer empty
  320.                 mov  TPFError,0                ;0 = not extended code
  321.                 or   al,al                      ;test for extended code
  322.                 jne  nextkeyl1                  ;quit if ascii code
  323.                 inc  TPFError                  ;1 = extended code
  324.                 mov  al,ah                      ;move extended code to al
  325. nextkeyl1:      ret     
  326. nextkey endp
  327.  
  328.  
  329. ;-------------------------------------------------------------------------------
  330. ;function lastkey :char;
  331. ;-------------------------------------------------------------------------------
  332. ;
  333. lastkey proc far
  334.                 mov  ah,6                       ;dos func to chk for key
  335.                 mov  dl,0ffh                    ;subfunction number
  336.                 int  21h                        ;seek a keystroke
  337.                 jnz  lastkey1                   ;jump if keystroke found
  338.                 mov  al,0ffh                    ;else flag  that no char
  339. lastkey1:       ret
  340. lastkey endp
  341.  
  342.  
  343. ;-------------------------------------------------------------------------------
  344. ;function numlockdown: boolean;
  345. ;-------------------------------------------------------------------------------
  346. ;
  347. numlockdown proc far
  348.                 sub  ax,ax                      ;clear ax
  349.                 mov  es,ax                      ;point es to 0000:0000
  350.                 mov  si,418h                    ;offset of status byte
  351.                 mov  bl,32                      ;test bit 5
  352.                 mov  al,1                       ;true value
  353.                 test es:[si],bl                 ;test the bit
  354.                 jnz  nl1                        ;jump if true
  355.                 mov  al,0                       ;false value
  356. nl1:            ret
  357.  
  358. numlockdown endp
  359.  
  360.  
  361. ;-------------------------------------------------------------------------------
  362. ;function numlockon: boolean;
  363. ;-------------------------------------------------------------------------------
  364. ;
  365. numlockon proc far
  366.                 mov  ah,2                       ;bios kybd status func
  367.                 int  16h                        ;call the interrupt
  368.                 mov  bl,1                       ;true value
  369.                 test al,32                      ;test bit 5
  370.                 jnz  numlockonl1                ;jump if true
  371.                 mov  bl,0                       ;false value
  372. numlockonl1:    mov  al,bl                      ;place value for return
  373.                 ret
  374. numlockon endp
  375.  
  376.  
  377. ;-------------------------------------------------------------------------------
  378. ;function rightshiftdown: boolean;
  379. ;-------------------------------------------------------------------------------
  380. ;
  381. rightshiftdown proc far
  382.                 mov  ah,2                       ;bios kybd status func
  383.                 int  16h                        ;call the interrupt
  384.                 mov  bl,1                       ;true value
  385.                 test al,1                       ;test bit 0
  386.                 jnz  rightshiftdownl1           ;jump if true
  387.                 mov  bl,0                       ;false value
  388. rightshiftdownl1:       mov  al,bl              ;place value for return
  389.                 ret
  390. rightshiftdown endp
  391.  
  392.  
  393. ;-------------------------------------------------------------------------------
  394. ;function scrolllockdown: boolean;
  395. ;-------------------------------------------------------------------------------
  396. ;
  397. scrolllockdown proc far
  398.                 sub  ax,ax                      ;clear ax
  399.                 mov  es,ax                      ;point es to 0000:0000
  400.                 mov  si,418h                    ;offset of status byte
  401.                 mov  bl,16                      ;test bit 4
  402.                 mov  al,1                       ;true value
  403.                 test es:[si],bl                 ;test the bit
  404.                 jnz  scrollldownl1              ;jump if true
  405.                 mov  al,0                       ;false value
  406. scrollldownl1:  ret
  407. scrolllockdown endp
  408.  
  409.  
  410. ;-------------------------------------------------------------------------------
  411. ;function scrolllockon: boolean;
  412. ;-------------------------------------------------------------------------------
  413. ;
  414. scrolllockon proc far
  415.                 mov  ah,2                       ;bios kybd status func
  416.                 int  16h                        ;call the interrupt
  417.                 mov  bl,-1                      ;true value
  418.                 test al,16                      ;test bit 4
  419.                 jnz  scrolllockonl1             ;jump if true
  420.                 mov  bl,0                       ;false value
  421. scrolllockonl1: mov  al,bl                      ;place value for return
  422.                 ret
  423. scrolllockon endp
  424.  
  425.  
  426. ;-------------------------------------------------------------------------------
  427. ;procedure setcapslock;
  428. ;-------------------------------------------------------------------------------
  429. ;
  430. setcapslock proc far
  431.                 sub  ax,ax                      ;clear ax
  432.                 mov  es,ax                      ;es pts to 0000:0000
  433.                 mov  al,64                      ;bit 6
  434.                 or   es:[417h],al               ;set the bit
  435.                 ret
  436. setcapslock endp
  437.  
  438.  
  439. ;-------------------------------------------------------------------------------
  440. ;procedure setins;
  441. ;-------------------------------------------------------------------------------
  442. ;
  443. setins  proc far
  444.                 sub  ax,ax                      ;clear ax
  445.                 mov  es,ax                      ;es pts to 0000:0000
  446.                 mov  al,128                     ;bit 7
  447.                 or   es:[417h],al               ;set the bit
  448.                 ret
  449. setins  endp
  450.  
  451.  
  452.  
  453. ;-------------------------------------------------------------------------------
  454. ;procedure setnumlock;
  455. ;-------------------------------------------------------------------------------
  456. ;
  457. setnumlock proc far
  458.                 sub  ax,ax                      ;clear ax
  459.                 mov  es,ax                      ;es pts to 0000:0000
  460.                 mov  al,32                      ;bit 5
  461.                 or   es:[417h],al               ;set the bit
  462.                 ret
  463. setnumlock endp
  464.  
  465.  
  466. ;-------------------------------------------------------------------------------
  467. ;procedure setscrolllock;
  468. ;-------------------------------------------------------------------------------
  469. ;
  470. setscrolllock proc far
  471.                 sub  ax,ax                      ;clear ax
  472.                 mov  es,ax                      ;es pts to 0000:0000
  473.                 mov  al,16                      ;bit 4
  474.                 or   es:[417h],al               ;set the bit
  475.                 ret
  476. setscrolllock endp
  477.  
  478. code    ends
  479.         end
  480.